package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Register extends Activity {
	private EditText name;
	private EditText userName;
	private EditText password;
	private EditText email;
	private Button save;
	private RegisterManager regisMgr;
	private LoginManager loginMgr;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.signup);
		name = (EditText) findViewById(R.id.editText_signup_name);
		userName = (EditText) findViewById(R.id.editText_signup_user);
		password = (EditText) findViewById(R.id.editText_signup_password);
		email = (EditText) findViewById(R.id.editText_signup_email);
		save = (Button) findViewById(R.id.button_signup_save);
		regisMgr = new RegisterManager(Register.this, null, null, 1);
		loginMgr = new LoginManager(Register.this, null, null, 1);

		save.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				RegisterBean rigis = new RegisterBean(name.getText().toString(),
						userName.getText().toString(), password.getText()
								.toString(), email.getText().toString());
				regisMgr.insertRegister(rigis);
				LoginBean login = new LoginBean();
				login.setUsername(userName.getText().toString());
				login.setPassword(password.getText().toString());
				loginMgr.insertLogin(login);
				Intent gotoMain  = new Intent(Register.this,MainActivity.class);
				startActivity(gotoMain);

			}
		});

	}
}
